/*
 * Flashlib - QB9 common Flash library
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

 
package com.qb9.flashlib.net
{
	/** Constants for the differnet file formats. */
	public class LoadFileFormat
	{
		public static const INFER:String = 'infer';
		public static const XML:String = 'xml';
		public static const SOUND:String = 'sound';
		public static const SWF:String = 'swf';
		public static const PLAIN_TEXT:String = 'plainText';
		public static const JSON:String = 'json';
		public static const IMAGE:String = 'image';
		public static const BINARY:String = 'binary';
		public static const VARIABLES:String = 'variables';
		
		private static const END:RegExp = /[#?].*$/;
		
		/** Infer the file format from the file extension. */
		public static function infer(url:String) : String
		{
			var ext:String = url.replace(END, '').split('.').pop();

			switch(ext)
			{
				case 'swf': 
					return SWF;
				case 'jpg':
				case 'jpeg':
				case 'png':
				case 'pneg':
				case 'gif':
				case 'bmp': 
					return IMAGE;
				case 'mp3':
				case 'wav': 
					return SOUND;
				case 'xml': 
					return XML;
				case 'json':
					return JSON;
				default:
					return PLAIN_TEXT; 
			}
		}
	}
}
